﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using HRProject.Code.Common;
using HRProject.Code.DTO;
using System.Collections.Generic;
using HRProject.Code.DAO;

namespace HRProject.Task
{
    public partial class ManageTask : System.Web.UI.Page
    {
        private int year;
        private int month;
        private List<BLTask> tasks;

        public List<BLTask> Tasks
        {
            get { return tasks; }
            set { tasks = value; }
        }

        public int Month
        {
            get { return month; }
            set { month = value; }
        }

        public int Year
        {
            get { return year; }
            set { year = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser user = Membership.GetUser();
            Guid userId;
            if (user != null)
            {
                userId = (Guid)user.ProviderUserKey;
            }
            else
            {
                userId = Guid.NewGuid();
            }
            string strYear = Request.Params["year"];
            if (!int.TryParse(strYear, out year))
            {
                year = DateTime.Now.Year;
            }
            else if ((year < DateTime.MinValue.Year) || (year > DateTime.MaxValue.Year))
            {
                year = DateTime.Now.Year;
            }

            string strMonth = Request.Params["month"];
            if (!int.TryParse(strMonth, out month))
            {
                month = DateTime.Now.Month;
            }
            else if ((month < DateTime.MinValue.Month) || (month > DateTime.MaxValue.Month))
            {
                month = DateTime.Now.Month;
            }

            TaskDAO dao = new TaskDAO();
            tasks = dao.findForMonthDisplay(userId, year, month);
        }
    }
}
